

* Open log
capture log close
log using "Data analysis\cbld-management04-exp03.log", replace text


* *****************************************************************************
* Processing of results of computational experiment 3 for further data analysis
* *****************************************************************************

* Programme:	cbld-management04-exp03.do
* Project:		Council coalition building
* Author:		Frank Haege, Department of Politics and Administration, University of Limerick
* Contact:		frank.haege@ul.ie

* Description
*************
* This do-file uses the simulation results of the third computational experiment to 
* generate data sets of predicted consensus rates and consensus rates expected by chance.


* Set up Stata
version 11
clear all
macro drop _all
set linesize 80
set more off

* Load data set
use "Experiments\Experiment03\cbld-model-121020-exp03.dta", clear

* Generate dichotomous consensus variable
generate consensus = 0
replace consensus = 1 if noblock == nostates
label var consensus "Consensus decision"
tab consensus, m

* Generate regime variable
label var regime "Regime"
label def regimel /*
	*/ 1 "Member States and Voting Threshold set by slider" /*
	*/ 2 "Pre-1995: 12 Member States, pre-Nice Rules" /*
	*/ 3 "1995-2003: 15 Member States, pre-Nice Rules" /*
	*/ 4 "2005-2006: 25 Member States, Nice Rules (votes)" /*
	*/ 5 "2005-2006: 25 Member States, Nice Rules (votes & population)" /*
	*/ 6 "2005-2006: 25 Member States, Nice Rules (votes & population & states)" /*
	*/ 7 "2005-2006: 25 Member States, Nice Rules (population)" /*
	*/ 8 "2005-2006: 25 Member States, Nice Rules (population & votes)" /*
	*/ 9 "2005-2006: 25 Member States, Nice Rules (population & votes & states)" /*
	*/ 10 "2007-2013: 27 Member States, Nice Rules (votes)" /*
	*/ 11 "2007-2013: 27 Member States, Nice Rules (votes & population)" /*
	*/ 12 "2007-2013: 27 Member States, Nice Rules (votes & population & states)" /*
	*/ 13 "2007-2013: 27 Member States, Nice Rules (population)" /*
	*/ 14 "2007-2013: 27 Member States, Nice Rules (population & votes)" /*
	*/ 15 "2007-2013: 27 Member States, Nice Rules (population & votes & states)" /*
	*/ 16 "Post-2014: 27 Member States, Lisbon Rules (votes)" /*
	*/ 17 "Post-2014: 27 Member States, Lisbon Rules (votes & states)" /*
	*/ 18 "Post-2014: 27 Member States, Lisbon Rules (votes & states & minority)"
label val regime regimel
tab regime, m


* Generate data sets of predicted consensus rates and consensus rates expected by chance
****************************************************************************************

* Collapse data by combination of move sequence and regime
sort sequence regime
collapse (mean) consensus=consensus nostates=nostates, by(sequence regime)
label var consensus "Expected consensus (model)"
label var nostates "Number of member states"

* Generate standard error of proportion
generate se = sqrt(consensus*(1-consensus)/1000)
label var se "Standard error (model)"

* Generate lower and upper bound of confidence interval
generate lowerci = (consensus - (1.96 * se))
label var lowerci "CI lower bound (model)"
generate upperci = (consensus + (1.96 * se))
label var upperci "CI upper bound (model)"
	
* Generate rule-member state period variable
generate rulemembersize = .
replace rulemembersize = 1 if regime == 2
replace rulemembersize = 2 if regime == 3
replace rulemembersize = 3 if regime > 3 & regime <= 9
replace rulemembersize = 4 if regime > 9 & regime <= 15
replace rulemembersize = 5 if regime > 15
label var rulemembersize "Rule-membership period"
label define rulemembersizel /*
	*/ 1 "Pre-Nice 12" /*
	*/ 2 "Pre-Nice 15" /*
	*/ 3 "Nice 25" /*
	*/ 4 "Nice 27" /*
	*/ 5 "Lisbon 27", modify
label val rulemembersize rulemembersizel

* Merge with expected consensus rates data
merge m:1 nostates using "Experiments\Other data\cbld-management02.dta"
drop _merge

* Generate dataset based on model with weighted votes and random execution
sort sequence regime
preserve
	* Drop redundant data points
	keep if regime == 2 | regime == 3 | regime == 4
	keep if sequence == 1

	* Save data set
	sort rulemembersize
	save "Experiments\Experiment03\cbld-management04-exp03a1.dta", replace
restore

* Generate dataset based on model with weighted votes and sequence execution
preserve
	* Drop redundant data points
	keep if regime == 2 | regime == 3 | regime == 4
	keep if sequence == 2

	* Save data set
	sort rulemembersize
	save "Experiments\Experiment03\cbld-management04-exp03b1.dta", replace
restore

* Generate dataset based on model with weighted votes, population threshold (under Nice), and random execution
preserve
	* Drop redundant data points
	keep if regime == 2 | regime == 3 | regime == 5
	keep if sequence == 1

	* Save data set
	sort rulemembersize
	save "Experiments\Experiment03\cbld-management04-exp03a2.dta", replace
restore

* Generate dataset based on model with weighted votes, population threshold (under Nice), and sequence execution
preserve
	* Drop redundant data points
	keep if regime == 2 | regime == 3 | regime == 5
	keep if sequence == 2

	* Save data set
	sort rulemembersize
	save "Experiments\Experiment03\cbld-management04-exp03b2.dta", replace
restore

* Generate dataset based on model with weighted votes, population and member state threshold (under Nice), and random execution
preserve
	* Drop redundant data points
	keep if regime == 2 | regime == 3 | regime == 6
	keep if sequence == 1

	* Save data set
	sort rulemembersize
	save "Experiments\Experiment03\cbld-management04-exp03a3.dta", replace
restore

* Generate dataset based on model with weighted votes, population and member state threshold (under Nice), and sequence execution
preserve
	* Drop redundant data points
	keep if regime == 2 | regime == 3 | regime == 6
	keep if sequence == 2

	* Save data set
	sort rulemembersize
	save "Experiments\Experiment03\cbld-management04-exp03b3.dta", replace
restore

* Save data set
sort sequence regime
compress
save "Experiments\Experiment03\cbld-management04-exp03.dta", replace


* Exit do-file
log close
exit
